
//   验证电话号码
export function validatePhone(rule, value, callback) {
  // const reg =
  // eslint-disable-next-line eqeqeq
  if (value === '' || value === undefined || value === 'null' || value === null) {
    callback(new Error('请输入电话号码'))
  } else {
    // eslint-disable-next-line eqeqeq
    if ((!/^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$/.test(value)) && value !== '') {
      callback(new Error('请输入正确的电话号码'))
    } else {
      callback()
    }
  }
}
//   验证电话号码
export function validatePhone2(rule, value, callback) {
  // const reg =
  // eslint-disable-next-line eqeqeq

  // eslint-disable-next-line eqeqeq
  if ((!/^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$/.test(value)) && value !== '') {
    callback(new Error('请输入正确的电话号码'))
  } else {
    callback()

  }
}

//   密码校检
export const validatePsdReg = (rule, value, callback) => {
  if (!value) {
    return callback(new Error('请输入密码'))
  }
  if (!/^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$)([^\u4e00-\u9fa5\s]){6,10}$/.test(value)) {
    callback(new Error('请输入6-10位字母、数字或者符号组合'))
  } else {
    callback()
  }
}

// 邮箱验证
export const validateEaiReg = (rules, value, callback) => {
  if (value === '' || value === 'null' || value === null || value === undefined) {
    callback()
  } else {
    if ((!/^\w+((-\w+)|(\.\w+))*@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/.test(value))) {
      callback(new Error('请输入正确的邮箱地址'))
    } else {
      callback()
    }
  }
}

export const validateNamReg = (rule, value, callback) => {
  if (value === '' || value === null || value === undefined) {
    callback(new Error('请输入账号'))
  } else {
    callback()
  }
}



export const validatePass = (rule, value, callback) => {
  if (value === "") {
    callback(new Error("请输入密码"));
  } else {
    if (this.registerForm.checkPass !== "") {

      setInterval(() => {
        this.$refs.registerForm.validateField("checkPass");
      }, 100)
    }
    callback();
  }
}
export const validatePass2 = (rule, value, callback) => {
  if (value === "") {
    callback(new Error("请再次输入密码"));
  } else if (value !== this.registerForm.pass) {
    callback(new Error("两次输入密码不一致!"));
  } else {
    callback();
  }
}

export const validateAge = (rule, value, callback) => {
  if (value === '' || value === 'null' || value === null || value === undefined || value === "未知") {
    callback()
  }
  setTimeout(() => {
    if (!Number.isInteger(value)) {
      callback(new Error("请输入0-200的整数"));
    } else {
      if (value < -1 || value > 200) {
        callback(new Error("请输入0-200的整数"));
      } else {
        callback();
      }
    }
  }, 100);

}
export const validateAge2 = (rule, value, callback) => {
  if (!value) {
    callback(new Error('请输入0-200的数字，-1 表示你想保密'))
  } else if (value == -1) { callback() } else {
    setTimeout(() => {
      let reg = /^[0-9]*$/
      if (!reg.test(value)) {
        callback(new Error("请输入0-200的数字，-1 表示你想保密"));
      } else {
        if (value < -1 || value > 200) {
          callback(new Error("请输入0-200的数字，-1 表示你想保密"));
        } else {
          callback();
        }
      }
    }, 100);
  }
}
export const validateUseraccount = (rule, value, callback) => {
  let wordreg = /^[a-zA-Z]/
  let reg = /^[a-zA-z](?!^[\d]+$)(?!^[-]+$)(?!^[_]+$)(?!^[a-zA-Z]+$)[\w-]{6,30}$/
  if (!value) {
    callback(new Error("账号名不可为空"))
  } else if (!wordreg.test(value)) {
    callback(new Error("只能以字母开头"))
  } else if (!reg.test(value)) {
    callback(new Error("必须是 6-30 个字母、数字、下划线、减号或其组合"))
  } else {
    callback()
  }
}

export const validateSmscode = (rule, value, callback) => {
  let reg = /^\d{6}$/;
  if (!value) {
    callback(new Error("请输入验证码"));
  } else if (!reg.test(value)) {
    callback(new Error("请输入6位数字验证码"));
  } else {
    callback();
  }
};